﻿using System.Collections;
using System.Collections.Generic;
using System.ServiceModel;
using System.Web;

namespace GlimpseWcf.Server
{
    public class OperationContextWrapper : IExtension<OperationContext>
    {
        private readonly IDictionary _items;
        private readonly HttpCookieCollection _cookies;
        
        private OperationContextWrapper()
        {
            _items = new Dictionary<string,object>();
            _cookies = new HttpCookieCollection();
        }

        public IDictionary Items{ get { return _items; } }
        public HttpCookieCollection Cookies { get { return _cookies; } }

        public static OperationContextWrapper Current
        {
            get
            {
                var context = OperationContext.Current.Extensions.Find<OperationContextWrapper>();
                if (context == null)
                {
                    context = new OperationContextWrapper();
                    OperationContext.Current.Extensions.Add(context);
                }
                return context;
            }
        }

        public void Attach(OperationContext owner) { }
        public void Detach(OperationContext owner) { }
    }
}